package com.sooncode.project.focusservice.controller;

import com.sooncode.project.core.finder.Page;
import com.sooncode.project.focusservice._.base.Utils;
import com.sooncode.project.focusservice.model.Classes;
import com.sooncode.project.focusservice.service.ClassesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RefreshScope
@RequestMapping("classes")
public class ClassesController {
    @Autowired
    ClassesService service;
    @PostMapping("class")
    public boolean add(@RequestParam Map map){
        return service.add(map);
    }

    @PutMapping("class")
    public boolean modify(@RequestParam String id,@RequestParam Map map){
        return service.modify(id,map);
    }

    @DeleteMapping("class")
    public boolean delete(@RequestParam String[] ids){
        for(String id:ids){
            service.delete(id);
        }
        return true;
    }

    @GetMapping("class")
    public Classes getById(@RequestParam String id) {
        return service.getById(id);
    }

    @GetMapping("classList")
    public List<Classes> getClassesList(@RequestParam String orgId){
        return service.getClassesList(orgId);
    }
    @GetMapping("classes")
    public Page<Classes> getPageList(@RequestParam int pageSize, @RequestParam int pageIndex, @RequestParam Map map){
        map.remove("pageSize");
        map.remove("pageIndex");
        Utils.mapValueTrim(map);
        return service.getPageList(pageSize,pageIndex-1,map);
    }
}
